package com.lua.event;

import com.helper.Debug;
import com.nioserver.operations.Handler;
import com.nioserver.lib.IMessageProcessor;
import com.nioserver.linklayer.Server;
import com.nioserver.io.DataReaderFactory;

import java.io.IOException;

public class createServer extends JSONEvent {


//    @Override
//    public String doSomething(Message.Words msg) throws InvalidProtocolBufferException {
//
//        ByteString data = msg.getData();
////        JSONObject
//        Message.Json json = Message.Json.parseFrom(data.toByteArray());
//        JSONObject jj = JSONObject.fromObject(json);
//        String port = jj.getString("port");
//        IMessageProcessor messageProcessor = new Handler();
//        Server server = new Server(new Integer(port),
//                new DataReaderFactory(),
//                messageProcessor);
//        try {
//            server.start();
//            Debug.log("beigin the service ... ","port",port);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        return "";
//    }

    @Override
    public String op(String jb) {

        IMessageProcessor messageProcessor = new Handler();

        Server server = new Server( parseInt(jb),
                new DataReaderFactory(),
                messageProcessor);
        try {
            server.start();
            Debug.log("beigin the service ... ","port",jb);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "success";
    }
}
